<!-- #include file="aspuploader/include_aspuploader.asp" -->
<script runat="server" language="JScript" src="galleryimpl.js"></script>
<script runat="server" language="JScript">

var AspGallery_ImagingMethod="Warning"

var AspGallery_ImagingMethod_WarningText="Warning - Please modify the AspGallery_ImagingMethod before create the asp gallery object."

// return a string "width,height" , for example , "1024,768"
function AspGallery_GenerateThumbnail(imagepath,thumbpath,thumbwidth,thumbheight,impl)
{
	switch(AspGallery_ImagingMethod)
	{
		case "ActiveX":
			var helper=new ActiveXObject("CuteSoft.AspImaging.ImageHelper");
			return helper.GenerateThumbnail(imagepath,thumbpath,thumbwidth,thumbheight);
		case "AspNetService":
			return AspGallery_GenerateThumbnail_AspNetService(imagepath,thumbpath,thumbwidth,thumbheight,impl);
		default:
			throw(new Error(AspGallery_ImagingMethod_WarningText));
	}
}

function CheckImagingMethodAndShowWarning()
{
	if(String(Request.QueryString("GalleryAjaxInvoke"))=="1")
		return;
	
	if(AspGallery_ImagingMethod=="Warning")
	{
		Response.Write("<h1>"+AspGallery_ImagingMethod_WarningText+"</h1>");
		return;
	}
}

function AspGallery_GenerateThumbnail_AspNetService(imagepath,thumbpath,thumbwidth,thumbheight,impl)
{
	var url=impl.GalleryClient+"/thumb.aspx";
	
	//https get 800C0019/-2146697191 error.
	//var ssl=String(Request.ServerVariables("SERVER_PORT_SECURE"))=="1";
	//url=(ssl?"https://":"http://")+String(Request.ServerVariables("HTTP_HOST"))+url;
	
	url="http://"+String(Request.ServerVariables("HTTP_HOST"))+url;
	
	var jobfile=imagepath+".job.config";
	var xm=new ActiveXObject("Microsoft.XMLDOM");
	xm.loadXML("<GenerateThumbnail />");
	xm.documentElement.setAttribute("ImagePath",imagepath);
	xm.documentElement.setAttribute("ThumbPath",thumbpath);
	xm.documentElement.setAttribute("ThumbWidth",thumbwidth);
	xm.documentElement.setAttribute("ThumbHeight",thumbheight);
	xm.save(jobfile);
	
	var xh=new ActiveXObject("Microsoft.XMLHTTP");
	xh.open("POST",url+"?job="+escape(jobfile),false);
	xh.send("");
	
	xm.load(jobfile);
	var err=xm.documentElement.getAttribute("Error");
	if(err)
		throw(new Error(err));
	
	var width=xm.documentElement.getAttribute("Width");
	var height=xm.documentElement.getAttribute("Height");
	
	if(!width||!height)
	{
		if(xh.status!=200)
			throw(new Error("thumb.aspx returns http "+xh.status +" error : \r\n " + xh.responseText));
		throw(new Error("unknown error! thumb.aspx does not work correctly."));
	}
	
	var FSO=new ActiveXObject("Scripting.FileSystemObject");
	FSO.DeleteFile(jobfile);
	
	return width+","+height;
}

</script>
<script runat=server language=VBScript>

Class AspGallery
	
	Private internalimpl
	
	Public Property Get Impl
		If internalimpl = EMPTY Then
			Set internalimpl=AspGalleryCreateCoreImplemenation(Me)
		End If
		Set Impl=internalimpl
	End Property
	

	Private Sub Class_Initialize()
		CheckImagingMethodAndShowWarning()
	End Sub
	

	Public Property Get Uploader
		Set Uploader=Impl.Uploader
	End Property
	
	Public Property Get GalleryFolder
		GalleryFolder=Impl.GalleryFolder
	End Property
	Public Property Let GalleryFolder(val)
		Impl.GalleryFolder=val
	End Property
	
	Public Property Get AllowEdit
		AllowEdit=Impl.AllowEdit
	End Property
	Public Property Let AllowEdit(val)
		Impl.AllowEdit=val
	End Property
	
	Public Property Get AllowPostComment
		AllowPostComment=Impl.AllowPostComment
	End Property
	Public Property Let AllowPostComment(val)
		Impl.AllowPostComment=val
	End Property
	
	Public Property Get AllowShowComment
		AllowShowComment=Impl.AllowShowComment
	End Property
	Public Property Let AllowShowComment(val)
		Impl.AllowShowComment=val
	End Property

	Public Property Get LogonUserID
		LogonUserID=Impl.LogonUserID
	End Property
	Public Property Let LogonUserID(val)
		Impl.LogonUserID=val
	End Property
	
	Public Property Get LogonUserName
		LogonUserName=Impl.LogonUserName
	End Property
	Public Property Let LogonUserName(val)
		Impl.LogonUserName=val
	End Property
	
	Public Property Get Layout
		Layout=Impl.Layout
	End Property
	Public Property Let Layout(val)
		Impl.Layout=val
	End Property
	
	Public Property Get Editor
		Editor=Impl.Editor
	End Property
	Public Property Let Editor(val)
		Impl.Editor=val
	End Property
	
	Public Property Get Slider
		Slider=Impl.Slider
	End Property
	Public Property Let Slider(val)
		Impl.Slider=val
	End Property
	
	Public Property Get Viewer
		Viewer=Impl.Viewer
	End Property
	Public Property Let Viewer(val)
		Impl.Viewer=val
	End Property
	
	Public Property Get Popup
		Popup=Impl.Popup
	End Property
	Public Property Let Popup(val)
		Impl.Popup=val
	End Property
	
	Public Property Get Theme
		Theme=Impl.Theme
	End Property
	Public Property Let Theme(val)
		Impl.Theme=val
	End Property
	
	Public Property Get Width
		Width=Impl.Width
	End Property
	Public Property Let Width(val)
		Impl.Width=val
	End Property

	Public Property Get Height
		Height=Impl.Height
	End Property
	Public Property Let Height(val)
		Impl.Height=val
	End Property
	
	Public Property Get ClientID
		ClientID=Impl.ClientID
	End Property
	Public Property Let ClientID(val)
		Impl.ClientID=val
	End Property

	
	Public Function Render()
		Response.Write(Me.GetString())
	End Function
	
	Public Function GetString()
		GetString = Impl.GetString()
	End Function
	
	Public Function ProcessAjaxPostback()
		Impl.ProcessAjaxPostback()
	End Function
	
	Public Function CreateAspUploader()
		Set CreateAspUploader=new AspUploader
	End Function

	Public Function SetSession(name,value)
		Session(name) = value
	End Function
	Public Function SetApplication(name,value)
		Application(name) = value
	End Function
	
	Public Function BinToHex(bytes)
		Dim bslen,i,b,l,h,chars,sb
		chars="0123456789ABCDEF"
		sb=""
		For i=1 To LenB(bytes)
			b=AscB(MidB(bytes,i,1))
			l=b Mod 16
			h=(b-l)/16
			sb = sb & Mid(chars,h+1,1) & Mid(chars,l+1,1)
		Next
		BinToHex=sb
	End Function
	
End Class



</script>
